
// <copyright file="CounterEnumeratorDecorator.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   The counter enumerator.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Collections.Generic
{
    using System.Collections;
    using System.Collections.Generic;

    /// <summary>
    /// The counter enumerator.
    /// </summary>
    /// <typeparam name="T">
    /// </typeparam>
    public sealed class CounterEnumeratorDecorator<T> : IEnumerator<T>
    {
        #region Fields

        /// <summary>
        /// The enumerator.
        /// </summary>
        private readonly IEnumerator<T> _enumerator;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="CounterEnumeratorDecorator{T}"/> class.
        /// </summary>
        /// <param name="enumerator">
        /// The enumerator.
        /// </param>
        public CounterEnumeratorDecorator(IEnumerator<T> enumerator)
        {
            this._enumerator = enumerator;
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        /// Gets the current.
        /// </summary>
        public T Current
        {
            get
            {
                this.RedCount++;
                return this._enumerator.Current;
            }
        }

        /// <summary>
        /// Gets the red count.
        /// </summary>
        public int RedCount { get; private set; }

        #endregion Public Properties

        #region Explicit Interface Properties

        /// <summary>
        /// Gets the current.
        /// </summary>
        object IEnumerator.Current
        {
            get
            {
                this.RedCount++;
                return this._enumerator.Current;
            }
        }

        #endregion Explicit Interface Properties

        #region Public Methods and Operators

        /// <summary>
        /// The dispose.
        /// </summary>
        public void Dispose()
        {
            this._enumerator.Dispose();
        }

        /// <summary>
        /// The move next.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool MoveNext()
        {
            return this._enumerator.MoveNext();
        }

        /// <summary>
        /// The reset.
        /// </summary>
        public void Reset()
        {
            this._enumerator.Reset();
        }

        #endregion Public Methods and Operators
    }
}
